package com.wyk.security;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.realm.AuthenticatingRealm;
import org.springframework.beans.factory.annotation.Autowired;

import com.wyk.entity.RegisterUser;
import com.wyk.service.RegisterUserService;

public class AdminRealm extends AuthenticatingRealm {
	
	@Autowired
	private RegisterUserService registerUserService;
	
	@Override
	protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
		AuthenticationInfo info = new SimpleAuthenticationInfo( token.getPrincipal() ,  token.getCredentials() , "1111");
		RegisterUser registerUser = new RegisterUser();
		System.out.println(token.getPrincipal().toString());
		System.out.println(new String((char[])token.getCredentials()));
		System.out.println(info==null);
		System.out.println("====================");
		registerUser.setUserName(token.getPrincipal().toString());
		registerUser.setPassword(new String((char[])token.getCredentials()));
		registerUserService.setUserSession(registerUser);
		return info;
	}
}
